<?php
/*
 * @Author: 李志刚
 * @CopyRight: 2022-2099 李志刚（854378082@qq.com）
 * @Date: 2019-01-03 20:14:16
 * @Description: 部门表
 * @LastEditors: 李志刚
 * @LastEditTime: 2022-04-30 10:10:08
 * @FilePath: /CoinCMF/app/Models/Rbac/Department.php
 */

namespace App\Models\Rbac;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Department extends Model
{
    use HasFactory;
    /**
     * 关联到模型的数据表
     *
     * @var string
     */
    protected $table = 'ums_department';

    // 不可以批量赋值的字段，为空则表示都可以
    protected $guarded = [];

    /**
    * The attributes that are mass assignable.
    *
    * @var array
    */
    protected $hidden = [];

    /**
     * 表明模型是否应该被打上时间戳
     *
     * @var bool
     */
    public $timestamps = true;
    // 自动生成的时间要加时区约束
    public function serializeDate(DateTimeInterface $date): string
    {
        return $date->format('Y-m-d H:i:s');
    }
    /**
     * 应该被转换成原生类型的属性。
     *
     * @var array
     */
    protected $casts = [];

    /**
     * 用户
     */
    public function Admin()
    {
        return $this->belongsToMany('\App\Models\Rbac\Admin', 'ums_department_admin', 'department_id', 'admin_id');
    }
}
